package cn.linjianhui.thread.local;

import java.util.Random;
import java.util.concurrent.Callable;

public class RndTask implements Callable<Long> {
    private int mode = 0;

    public RndTask(int mode) {
        this.mode = mode;
    }

    public Random getRandom() {
        if(mode == 0) {
            return RandomDemo.rnd;
        }else if(mode == 1){
            return RandomDemo.tl.get();
        }else {
            return null;
        }
    }


    @Override
    public Long call() throws Exception {
        long b = System.currentTimeMillis();
        for(int i = 0; i < RandomDemo.GEN_COUNT; i++) {
            getRandom().nextInt();
        }
        long a = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName() + " speed" + (a - b) + "ms");
        return a - b;
    }
}
